Skip to content

fix(cli): support build --from local paths#556

Closed
jsdavid278-cyber wants to merge 2 commits into
profullstack:masterfrom
jsdavid278-cyber:patch-1
Closed

fix(cli): support build --from local paths#556
jsdavid278-cyber wants to merge 2 commits into
profullstack:masterfrom
jsdavid278-cyber:patch-1

Conversation

@jsdavid278-cyber
Copy link
Copy Markdown
Contributor

Summary

  • Add local path handling for sh1pt build --from <path>.
  • Validate missing paths and files before build summary generation.
  • Reuse stack detection so local projects report runtime/package manager/project name like cloned git repos.

Testing

  • Added Vitest coverage for local path detection, packageManager handling, and missing path errors.
  • Not run locally in this environment because npm/pnpm/git are unavailable.

Related to the CLI command implementation work requested in #133.

Add local path handling for sh1pt build --from, including stack detection and summary output.
Adds coverage for local directory stack detection, packageManager handling, and missing local path errors.
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 2, 2026

Greptile Summary

This PR adds support for sh1pt build --from <local-path>, introducing detectLocalPath for path validation and stack detection, and a shared printBuildSummary helper. As part of the same change, the goProjectName helper is removed and replaced with an inline expression that loses the major-version suffix stripping logic.

  • detectLocalPath: validates that the input exists and is a directory, then reuses detectStack to extract runtime/package-manager/project-name metadata — mirroring what the git branch already does with cloned repos.
  • printBuildSummary: new shared helper for formatting the build summary to stdout, but the existing git branch was not migrated to use it, leaving duplicate inline code.
  • goProjectName removal: the inline replacement modName.split('/').pop() omits the /vN suffix-stripping logic, causing versioned Go modules (e.g. github.com/user/app/v2) to report v2 as their project name.

Confidence Score: 3/5

The local-path feature itself works correctly, but the removal of goProjectName silently breaks project-name extraction for any Go module that uses a major-version path suffix.

The Go versioned-module name regression is a real, present defect on the changed code path: any go.mod with a /v2 (or higher) suffix will display the version segment as the project name instead of the actual module name.

packages/cli/src/commands/build.ts — specifically the Go stack-detection block and the unmigrated git summary branch

Important Files Changed

Filename Overview
packages/cli/src/commands/build.ts Adds detectLocalPath and printBuildSummary; wires kind='path' in the command action. The removal of goProjectName introduces a regression for versioned Go module paths (e.g. /v2 suffix becomes the project name).
packages/cli/src/commands/build.test.ts Adds two new tests for detectLocalPath (happy path and missing-path error). The 'path is a file' error branch in detectLocalPath is not covered.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[sh1pt build --from input] --> B{resolveInput}
    B --> C{input.kind}
    C -- git --> D[cloneAndDetect]
    D --> D1[spawnSync git clone]
    D1 --> D2[detectStack cloneDir]
    D2 --> D3[printBuildSummary inline]
    D3 --> D4{keepClone?}
    D4 -- no --> D5[rmSync cloneDir]
    D4 -- yes --> D6[return]
    D5 --> D6
    C -- path --> E[detectLocalPath NEW]
    E --> E1{input.exists and existsSync?}
    E1 -- no --> E2[throw: local path not found]
    E1 -- yes --> E3{statSync.isDirectory?}
    E3 -- no --> E4[throw: must be a directory]
    E3 -- yes --> E5[detectStack dir]
    E5 --> E6[printBuildSummary helper]
    E6 --> E7[return]
    C -- other --> F[stub log]
Loading

Comments Outside Diff (2)

  1. packages/cli/src/commands/build.ts, line 229-230 (link)

    P2 The stale TODO still lists kind==='path' even though that branch is now fully handled above. Remove the obsolete note to avoid confusing future contributors.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

  2. packages/cli/src/commands/build.ts, line 193-210 (link)

    P2 git branch still uses inline summary code

    printBuildSummary was added to centralise build-summary output, but the existing git branch was not migrated to use it — it still calls console.log directly six times. The two branches can now drift independently; for instance the git path omits the kleur.bold formatting applied by printBuildSummary.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "test(cli): cover build --from local path..." | Re-trigger Greptile

runtime: 'go',
packageManager: 'go',
projectName: modName ? goProjectName(modName) : undefined,
projectName: modName ? modName.split('/').pop() : undefined,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Go versioned-module name regression

The deleted goProjectName helper explicitly stripped major-version path segments before calling .split('/').pop(). The new inline expression skips that step, so a Go module declared as module github.com/user/my-go-app/v2 now returns "v2" as the project name instead of "my-go-app". Any Go monorepo or library that follows the standard vN major-version suffix convention will produce a misleading project name in the build summary.

Comment on lines +127 to +137
it('throws when a local --from path is missing', () => {
const dir = join(makeTempDir(), 'missing');

expect(() => detectLocalPath({
kind: 'path',
raw: dir,
value: dir,
inferredName: 'missing',
exists: false,
})).toThrow('local path not found');
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing test for "path is a file, not a directory" branch

detectLocalPath throws "local path must be a directory" when statSync shows the path is a regular file, but this error path has no corresponding test.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

4 similar comments
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

@ralyodio ralyodio closed this Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants